const api = require("../../utils/request");
Page({
  data: {

    login: {
      show: false,
      line: false,
      avatar: "",
      nickname: ""
    }
  },
  // 登录监听
  chooseAvatar(e) {
    wx.showLoading({
      title: '登录中',
    })
    api.userDoAdminLogin({}).then(res => {
      //console.log(res.data.data);
      wx.setStorageSync('loginState', true)
      wx.setStorageSync('token', res.data.data.token)
      wx.setStorageSync('avatar', res.data.data.avatar)
      wx.setStorageSync('nickname', res.data.data.nickname)
      this.setData({
        login: {
          show: true,
          line: true,
          avatar: wx.getStorageSync('avatar'),
          nickname: wx.getStorageSync('nickname')
        }
      })
      wx.hideLoading()
    })

  },
  // 基本信息
  basicClick() {
    console.log('基本信息监听');
  },
  // 匿名反馈
  feedbackClick() {
    console.log('匿名反馈监听');
  },
  // 关于我们
  aboutClick() {
    console.log('关于我们监听');
  },
  // 退出监听
  exitClick() {
    let that = this;
    wx.showModal({
      title: '提示',
      content: '确定退出登录吗？',
      success(res) {
        if (res.confirm) {
          that.setData({
            login: {
              show: false,
            }
          })
          wx.setStorageSync('loginState', false)
          wx.setStorageSync('token', "")
          wx.setStorageSync('avatar', "")
          wx.setStorageSync('nickname', "")
        }
      }
    })
  },
  onLoad() {
    if (wx.getStorageSync('loginState')) {
      this.setData({
        login: {
          show: true,
          line: true,
          avatar: wx.getStorageSync('avatar'),
          nickname: wx.getStorageSync('nickname')
        }
      })
    }

  }
})